using System;
using System.Collections.Generic;

namespace RuthlessConquest {
    public static class CollectionUtils {
        public static void RandomShuffle<T>(this IList<T> list, Func<int> randomIntGenerator) {
            for (int num = list.Count - 1; num > 0; num--) {
                int index = (int)(randomIntGenerator() * (long)(num + 1) / 2147483648u);
                T value = list[index];
                list[index] = list[num];
                list[num] = value;
            }
        }

        public static int FirstIndex<T>(this IEnumerable<T> collection, T value) {
            int num = 0;
            foreach (T item in collection) {
                if (Equals(item, value)) {
                    return num;
                }
                num++;
            }
            return -1;
        }

        public static int FirstIndex<T>(this IEnumerable<T> collection, Func<T, bool> predicate) {
            int num = 0;
            foreach (T item in collection) {
                if (predicate(item)) {
                    return num;
                }
                num++;
            }
            return -1;
        }
    }
}